var k_edit = true;
$(window).load(function() {
	$('a').click(function(event) {
		event.preventDefault();
	});
	CKEDITOR.on('instanceReady', function(evt) {
		var editor = evt.editor;
		CKFinder.setupCKEditor(editor, {
			basePath : '/ckfinder/',
			skin : 'v1'
		});	

	});
	$('.dashboard').click(function(event) {
		window.location = "/admin/dashboard/";
	});
	$('.go-back').click(function(event) {
		window.history.back();
	}); 
	var articleId;

	$('.forsubmit').click(function(event) {
//		console.dir($('#entity_title').text());
		var coverurl = $("#coverUrl").attr('src');
		var preview = CKEDITOR.instances.editor2.getData();
		var ckvalue3 = CKEDITOR.instances.editor3.getData();
		
//		console.dir(CKEDITOR.instances.editor2.getData());
 
		var submit = {
			type : "POST",
			dataType : "json",
			data : {
				title : $('#entity_title').text(),
				content : ckvalue3,
				summary : preview,
				coverURL : coverurl
			},
			success : function(data) {
				if (data && data.state && (data.state.indexOf("ERROR") != -1)) {
					return;
				} else {
					if (data.entity) {
						articleId = data.entity
					}
					alert("update successfully");
				}
			}
		};
 		if (articleId) {
			submit.url = '/article/' + articleId + '/edit/';
		}
		$.ajax(submit);

	});
});